﻿using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ProjetoFase2
{
    public partial class FormEditCertificate : Form
    {
        private Residence auxResi;
        private UserLogin userLogin;

        public FormEditCertificate(Residence auxResi, UserLogin userLogin)
        {
            InitializeComponent();

            this.Text += " - " + userLogin.Username;

            this.auxResi = auxResi;

            this.userLogin = userLogin;

            // establish the initial data
            txtAddress.Text = this.auxResi.Address;
            txtClient.Text = this.auxResi.Client;
            cmbCooling.SelectedIndex = this.auxResi.Cooling - 1;
            cmbHeating.SelectedIndex = this.auxResi.Heating - 1;
            cmbIsolation.SelectedIndex = this.auxResi.Isolation - 1;
            cmbCoverage.SelectedIndex =
                (this.auxResi.Coverage == "Telhado" ? 0 : (this.auxResi.Coverage == "Placa" ? 1 :
                (this.auxResi.Coverage == "Piso Superior" ? 2 : -1)));
            cmbGlasses.SelectedIndex =
                (this.auxResi.Glasses == "Simples" ? 0 : (this.auxResi.Glasses == "Duplos" ? 1 : -1));
            txtTopology.Text = this.auxResi.Topology;
            labelNome.Text = userLogin.Name;

            // chooses the level
            switch (userLogin.AccessLevel)
            {
                case 0:
                    labelNome.Text = labelNome.Text + " - Trainee";
                    break;
                case 1:
                    labelNome.Text = labelNome.Text + " - Técnico";
                    break;
                case 2:
                    labelNome.Text = labelNome.Text + " - Fiscal";
                    break;
            }
        }

        private void menuClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.Close();
        }

        private void menuConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                auxResi.Cooling = int.Parse(cmbCooling.Text);
                auxResi.Coverage = cmbCoverage.Text;
                auxResi.Glasses = cmbGlasses.Text;
                auxResi.Heating = int.Parse(cmbHeating.Text);
                auxResi.Isolation = int.Parse(cmbIsolation.Text);
                auxResi.Topology = txtTopology.Text;
                auxResi.Category = userLogin.AccessLevel;
				auxResi.Approved = 0;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception)
            {
                Console.WriteLine("Erro nao esperado!");
            }
        }

    }
}